#include "Junk.hpp"

/// The toUpper and toLower function work only on ascii character
char toUpper(char c) {
	if (c > 97 && c < 122) {
		c -= 32;
	}
	return c;
}

void toUpper(std::string &s) {
	for (char& c : s) {
		c = toUpper(c);
	}
}

char toLower(char c) {
	if (c > 65 && c < 90) {
		c += 32;
	}
	return c;
}

void toLower(std::string &s) {
	for (char& c : s) {
		c = toLower(c);
	}
}

// Return the file name in a path
std::string getNameInPath(const std::string &path) {
	if (path.rfind('\\') < path.rfind('/'))
	{
		return path.substr(path.rfind('\\') + 1);
	}
	if (path.rfind('\\') > path.rfind('/'))
	{
		return path.substr(path.rfind('/') + 1);
	}
	return "";
}

std::string getFileType(const std::string &s) {
	if (s.rfind('.') != std::string::npos )
	{
		return s.substr(s.rfind('.') + 1);
	}
	return "";
}

// Return file size in byte
long long getFileSize(const std::string &s) {
	std::ifstream st(s, std::ifstream::binary | std::ifstream::ate);
	return st.tellg();
}
